From: Joey Hess Date: Mon, 27 Jan 2025 19:54:24 +0000 (-0400) Subject: optimise literalOsPath X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~6^2~158^2~67 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/www.github.com/%22bookmarks:/?a=commitdiff_plain;h=98a0a9ddff677b295b186f471f5ee059e61ffe0c;p=git-annex.git optimise literalOsPath Taking a ShortByteString and using OverloadedStrings should avoid it being converted from a String. The reason there is no IsString instance for OsPath is presumably the bad behavior of IsString for ByteString on unicode btw. But literalOsPath won't be used with unicode in git-annex. Sponsored-by: unqueued --- diff --git a/Annex/Magic.hs b/Annex/Magic.hs index eec8b404af..ade8efd6ea 100644 --- a/Annex/Magic.hs +++ b/Annex/Magic.hs @@ -5,6 +5,7 @@ - Licensed under the GNU AGPL version 3 or higher. -} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE CPP #-} module Annex.Magic ( diff --git a/Assistant/Install/Menu.hs b/Assistant/Install/Menu.hs index 7308608bb4..04261838ef 100644 --- a/Assistant/Install/Menu.hs +++ b/Assistant/Install/Menu.hs @@ -5,6 +5,7 @@ - Licensed under the GNU AGPL version 3 or higher. -} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-tabs #-} diff --git a/Build/DesktopFile.hs b/Build/DesktopFile.hs index 3dd887d048..b69fd82854 100644 --- a/Build/DesktopFile.hs +++ b/Build/DesktopFile.hs @@ -6,6 +6,7 @@ - Licensed under the GNU AGPL version 3 or higher. -} +{-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-tabs #-} diff --git a/Config/Files.hs b/Config/Files.hs index fb0670bf39..14450fcc72 100644 --- a/Config/Files.hs +++ b/Config/Files.hs @@ -5,6 +5,7 @@ - Licensed under the GNU AGPL version 3 or higher. -} +{-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-tabs #-} module Config.Files where diff --git a/Utility/FreeDesktop.hs b/Utility/FreeDesktop.hs index 8259544377..71ec3a3c7b 100644 --- a/Utility/FreeDesktop.hs +++ b/Utility/FreeDesktop.hs @@ -10,6 +10,7 @@ - License: BSD-2-clause -} +{-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-tabs #-} module Utility.FreeDesktop ( diff --git a/Utility/OSX.hs b/Utility/OSX.hs index 1f14d30923..1bcbe4c628 100644 --- a/Utility/OSX.hs +++ b/Utility/OSX.hs @@ -5,6 +5,7 @@ - License: BSD-2-clause -} +{-# LANGUAGE OverloadedStrings #-} {-# OPTIONS_GHC -fno-warn-tabs #-} module Utility.OSX ( @@ -18,7 +19,9 @@ import Common import Utility.UserInfo autoStartBase :: String -> OsPath -autoStartBase label = literalOsPath "Library" literalOsPath "LaunchAgents" literalOsPath (label ++ ".plist") +autoStartBase label = literalOsPath "Library" + literalOsPath "LaunchAgents" + toOsPath label <> literalOsPath ".plist" systemAutoStart :: String -> OsPath systemAutoStart label = literalOsPath "/" autoStartBase label diff --git a/Utility/OsPath.hs b/Utility/OsPath.hs index 28e3040841..b487a2976d 100644 --- a/Utility/OsPath.hs +++ b/Utility/OsPath.hs @@ -46,10 +46,6 @@ instance OsPathConv FilePath where toOsPath = toOsPath . toRawFilePath fromOsPath = fromRawFilePath . fromOsPath -{- Used for string constants. -} -literalOsPath :: String -> OsPath -literalOsPath = toOsPath - #ifdef WITH_OSPATH instance OsPathConv RawFilePath where toOsPath = bytesToOsPath . S.toShort @@ -80,6 +76,10 @@ bytesFromOsPath = getPosixString . getOsString getSearchPath :: IO [OsPath] getSearchPath = map toOsPath <$> PB.getSearchPath +{- Used for string constants. -} +literalOsPath :: ShortByteString -> OsPath +literalOsPath = bytesToOsPath + #else {- When not building with WITH_OSPATH, use RawFilePath. -} @@ -97,4 +97,7 @@ instance OsPathConv ShortByteString where unsafeFromChar :: Char -> Word8 unsafeFromChar = fromIntegral . ord + +literalOsPath :: RawFilePath -> OsPath +literalOsPath = id #endif diff --git a/Utility/SshConfig.hs b/Utility/SshConfig.hs index 798a48148f..e341b73894 100644 --- a/Utility/SshConfig.hs +++ b/Utility/SshConfig.hs @@ -5,6 +5,8 @@ - License: BSD-2-clause -} +{-# LANGUAGE OverloadedStrings #-} + module Utility.SshConfig ( SshConfig(..), Comment(..), diff --git a/Utility/Tmp/Dir.hs b/Utility/Tmp/Dir.hs index fa61d30f5b..d6448ef749 100644 --- a/Utility/Tmp/Dir.hs +++ b/Utility/Tmp/Dir.hs @@ -7,6 +7,7 @@ {-# LANGUAGE CPP #-} {-# OPTIONS_GHC -fno-warn-tabs #-} +{-# LANGUAGE OverloadedStrings #-} module Utility.Tmp.Dir ( withTmpDir, diff --git a/Utility/Tor.hs b/Utility/Tor.hs index 1696d7c3cf..eeabbbae79 100644 --- a/Utility/Tor.hs +++ b/Utility/Tor.hs @@ -5,6 +5,8 @@ - Licensed under the GNU AGPL version 3 or higher. -} +{-# LANGUAGE OverloadedStrings #-} + module Utility.Tor ( OnionPort, OnionAddress(..), @@ -143,7 +145,7 @@ hiddenServiceHostnameFile appname uid ident = hiddenServiceSocketFile :: AppName -> UserID -> UniqueIdent -> OsPath hiddenServiceSocketFile appname uid ident = varLibDir toOsPath appname - toOsPath (show uid ++ "_" ++ ident) toOsPath "s" + toOsPath (show uid ++ "_" ++ ident) literalOsPath "s" -- | Parse torrc, to get the socket file used for a hidden service with -- the specified UniqueIdent. @@ -155,7 +157,7 @@ getHiddenServiceSocketFile _appname uid ident = parse [] = Nothing parse (("HiddenServiceDir":hsdir:[]):("HiddenServicePort":_hsport:hsaddr:[]):rest) | "unix:" `isPrefixOf` hsaddr && hasident (toOsPath hsdir) = - Just $ toOsPath $ drop (length "unix:") hsaddr + Just $ toOsPath $ drop (length ("unix:" :: String)) hsaddr | otherwise = parse rest parse (_:rest) = parse rest